package com.example.nophase.Fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.nophase.R;
import com.example.nophase.activity.ApplyForHomeActivity;
import com.example.nophase.activity.finance.CompleteInstructionsActivity;
import com.example.nophase.activity.finance.InstructionsActivity;
import com.example.nophase.activity.manager.AdultListActivity;
import com.example.nophase.common.LoginManager;
import com.example.nophase.entity.SysUserVO;

import butterknife.BindView;

public class FinanceHomeContentFragment extends Fragment {

    public Context context;
    @BindView(R.id.btn_3_layout)
    LinearLayout btn3Layout;
    @BindView(R.id.btn_1_layout)
    LinearLayout btn1Layout;
    @BindView(R.id.btn_2_layout)
    LinearLayout btn2Layout;


    private FinanceHomeContentFragment(Context context) {
        this.context = context;
    }

    public static FinanceHomeContentFragment newInstance(Context context) {
        FinanceHomeContentFragment fragment = new FinanceHomeContentFragment(context);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.finance_home_fragment_content, container, false);
        Button button2 = view.findViewById(R.id.btn_2);
        Button button1 = view.findViewById(R.id.btn_1);
        Button button3 = view.findViewById(R.id.btn_3);
        TextView btn3Text = view.findViewById(R.id.btn_3_text);
        LinearLayout btn3Layout =view.findViewById(R.id.btn_3_layout);
        LinearLayout btn1Layout =view.findViewById(R.id.btn_1_layout);
        LinearLayout btn2Layout =view.findViewById(R.id.btn_2_layout);
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.startActivity(new Intent(context, CompleteInstructionsActivity.class));
            }
        });


        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                context.startActivity(new Intent(context, InstructionsActivity.class));
            }
        });


        SysUserVO userVO = LoginManager.getUserInfo(context);
        if (userVO.getMoreInfo().isSpecialApp()) {
            btn3Text.setText("我的流程");
            button3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    context.startActivity(new Intent(context, ApplyForHomeActivity.class));
                }
            });
        } else if (userVO.getUsername().equals("郝结芳")) {
            btn3Text.setText("待审批");
            button3.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    context.startActivity(new Intent(context, AdultListActivity.class));
                }
            });
        } else {
            btn3Layout.setVisibility(View.GONE);
            btn3Layout.setRight(0);
            btn3Layout.setLeft(0);
            btn1Layout.setLeft(0);
            btn1Layout.setRight(0);
            btn2Layout.setLeft(0);
            btn2Layout.setRight(60);
        }

        return view;
    }
}
